/*
* $Id: ChangeQueenBeeOperation.cpp 336 2011-09-28 06:06:36Z volok-aleksej@yandex.ru $
*
* Copyright 2009-2011 by Volokitin Aleksey
* All rights reserved
*
*/
#include "Common/include.h"
#include "ChangeQueenBeeOperation.h"
#include "Database/TransactManager.h"
#include "Database/Tables/QueenBeeTable.h"

CChangeQueenBeeOperation::CChangeQueenBeeOperation(CTransactManager* pManager)
: m_pManager(pManager){}
CChangeQueenBeeOperation::~CChangeQueenBeeOperation(){}

std::tstring CChangeQueenBeeOperation::ExecuteOperation(IDatabase* pDatabase, IReader* pReader){
	CQueenBeeTable queenbee;
	int size;
	pReader->ReadInt(size);
	int lenData = 0;
	int idQueenBee;
	lenData = pReader->ReadInt(idQueenBee);
	queenbee.m_content.s_nId = m_pManager->GetRealId(
		CTransactManager::ID(CTransactManager::QUEEN_BEE, idQueenBee));
	lenData += pReader->ReadUTF(queenbee.m_content.s_strName);
	std::tstring strNameQueenBee = queenbee.m_content.s_strName;
	lenData += pReader->ReadUTF(queenbee.m_content.s_strDescription);
	int idFamily;
	lenData = pReader->ReadInt(idFamily);
	if(idFamily != 0)
		idFamily = m_pManager->GetRealId(CTransactManager::ID(CTransactManager::FAMILY, idFamily));
	queenbee.m_content.s_nIdFamily = idFamily;
	int idParentQueenBee;
	lenData += pReader->ReadInt(idParentQueenBee);
	if(idParentQueenBee != 0)
		idParentQueenBee = m_pManager->GetRealId(CTransactManager::ID(CTransactManager::QUEEN_BEE, idParentQueenBee));
	queenbee.m_content.s_nIdParentQueenBee = idParentQueenBee;
	lenData += pReader->ReadTime(queenbee.m_content.s_date);
	lenData += pReader->ReadInt((int&)queenbee.m_content.s_breed);
	lenData += pReader->ReadUTF(queenbee.m_content.s_strFert);
	lenData += pReader->ReadBool(queenbee.m_content.s_bDead);
	queenbee.UpdateValue(pDatabase);
	std::tstring strLog = ILanguageManager::GetLanguageManager()->GetString(CHANGE_QUEEN_BEE_LOG_ID);
	return strLog + _T(" ") + strNameQueenBee;
}

void CChangeQueenBeeOperation::Free(){
	delete this;
}
